package com.zoho.daliansheng.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zoho.daliansheng.common.U8SystemRecord;
import com.zoho.daliansheng.common.ZohoRecord;
import com.zoho.daliansheng.config.CRMPathConfig;
import com.zoho.daliansheng.config.DatasourceEnum;
import com.zoho.daliansheng.config.U8SystemPathConfig;
import com.zoho.daliansheng.dlcr.DlcrU8WebService;
import com.zoho.daliansheng.dlcr.DlcrU8WebServiceSoap;
import com.zoho.daliansheng.dlcr.QueryRetInfo;
import com.zoho.daliansheng.utils.CommonUtil;
import com.zoho.daliansheng.utils.CrmApiUtil;
import com.zoho.daliansheng.utils.getCrmFieldUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ProductServiceImpl implements ProductService {

    ZohoRecord zohoRecord;

    U8SystemRecord u8SystemRecord;

    U8SystemPathConfig u8SystemPathConfig;

    CRMPathConfig crmPathConfig;

    public ProductServiceImpl(ZohoRecord zohoRecord, U8SystemRecord u8SystemRecord, U8SystemPathConfig u8SystemPathConfig, CRMPathConfig crmPathConfig) {
        this.zohoRecord = zohoRecord;
        this.u8SystemRecord = u8SystemRecord;
        this.u8SystemPathConfig = u8SystemPathConfig;
        this.crmPathConfig = crmPathConfig;
    }

    @Override
    public void synProduct() {

        /*
         * 1 获取CRM 产品模块数据
         */
        List<String> fieldList = getCrmFieldUtil.getProductFieldList();
        List<JSONObject> crmData = CrmApiUtil.getModuleData(zohoRecord.getAccessToken(), crmPathConfig.getProductModuleName(), fieldList);

        // CRM 工厂产品转码模块数据
        List<String> filedList = getCrmFieldUtil.getGongchangTranferFieldList();
        List<JSONObject> transferList = CrmApiUtil.getModuleData(zohoRecord.getAccessToken(), crmPathConfig.getGongChangTransferModuleName(), filedList);

        /*
         * 2 同步ERP存货档案
         */
        try {
//            synU8Data(crmData, DatasourceEnum.GONG_CHANG.getWebServiceUrl(), DatasourceEnum.GONG_CHANG.getCompanyName(), DatasourceEnum.GONG_CHANG.getAccountCode(), transferList);
            synU8Data(crmData, DatasourceEnum.SU_ZHOU.getWebServiceUrl(), DatasourceEnum.SU_ZHOU.getCompanyName(), DatasourceEnum.SU_ZHOU.getAccountCode(), transferList);
            synU8Data(crmData, DatasourceEnum.CHANG_ZHOU.getWebServiceUrl(), DatasourceEnum.CHANG_ZHOU.getCompanyName(), DatasourceEnum.CHANG_ZHOU.getAccountCode(), transferList);
            synU8Data(crmData, DatasourceEnum.DA_LIAN.getWebServiceUrl(), DatasourceEnum.DA_LIAN.getCompanyName(), DatasourceEnum.DA_LIAN.getAccountCode(), transferList);
            synU8Data(crmData, DatasourceEnum.XIN_CAI_LIAO.getWebServiceUrl(), DatasourceEnum.XIN_CAI_LIAO.getCompanyName(), DatasourceEnum.XIN_CAI_LIAO.getAccountCode(), transferList);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void synU8Data(List<JSONObject> crmData, String webServiceUrl, String companyName, String accountCode, List<JSONObject> transferList) throws MalformedURLException {

        String synModuleName = crmPathConfig.getProductModuleName(); // 要同步的模块名称
        log.info("同步【" + companyName + "】");
        // 1 过滤CRM数据，只保留单一账套
        crmData = crmData.stream().filter(object -> Objects.nonNull(object.getString("AffiliatedCompany")) && object.getString("AffiliatedCompany").equals(companyName)).collect(Collectors.toList());

        // 2 模块最大版本号
        Map<String, String> map = CrmApiUtil.getMaxVersion(zohoRecord.getAccessToken(), synModuleName, accountCode);
        String versionCrmId = map.get("id");
        int maxVersion = Integer.parseInt(map.get("maxVersion"));

        // 3 获取ERP数据
        DlcrU8WebService webService = new DlcrU8WebService(new URL(webServiceUrl));
        DlcrU8WebServiceSoap api = webService.getDlcrU8WebServiceSoap();
        QueryRetInfo queryRetInfo = api.queryInventoryByVersion(maxVersion);
        int queryMaxVersion = queryRetInfo.getMaxVersion();
        JSONArray jsonArray = JSONArray.parseArray(queryRetInfo.getJson());
        if (jsonArray.size() > 0) {

            // 4 比较数据
            List<JSONObject> insertList = new ArrayList<>();
            List<JSONObject> updateList = new ArrayList<>();
            List<String> deleteList = new ArrayList<>();
            List<JSONObject> batchInventory = jsonArray.toJavaList(JSONObject.class);

            if (maxVersion == -1) {
                if (crmData.size() == 0) {
                    insertList = batchInventory;
                } else {
                    for (JSONObject erpData : batchInventory) {
                        String code = erpData.getString("cinvcode"); // 存货编码
                        List<JSONObject> searchList = crmData.stream().filter(object -> Objects.nonNull(object.getString("Product_Code")) &&
                                object.getString("Product_Code").equals(code) && object.getString("AffiliatedCompany").equals(companyName)).collect(Collectors.toList());

                        if (accountCode.equals(DatasourceEnum.GONG_CHANG.getAccountCode())) {  // 因为工厂会转码，所以要重新查询
                            List<JSONObject> filterList = transferList.stream().filter(obj -> obj.getString("Name").equals(code)).collect(Collectors.toList());
                            if (filterList.size() > 0) {
                                JSONObject jsonObject = filterList.get(0);
                                String crm_code = jsonObject.getString("crm_code"); // crm 中对应的编码
                                List<JSONObject> collect = crmData.stream().filter(object -> Objects.nonNull(object.getString("Product_Code")) &&
                                        object.getString("Product_Code").equals(crm_code) && object.getString("AffiliatedCompany").equals(companyName)
                                ).collect(Collectors.toList());
                                if (collect.size() > 0) {
                                    searchList = collect;
                                }
                            }
                        }
                        if (searchList.size() > 0) {
                            JSONObject jsonObject = searchList.get(0);
                            String crmId = jsonObject.getString("id");
                            erpData.put("crmId", crmId);
                            updateList.add(erpData);
                        } else {
                            insertList.add(erpData);
                        }
                    }
                }

            } else {
                for (JSONObject erpData : batchInventory) {
                    // sys_change_operation 该字段非常关键,记录了记录的变动类型,I=Insert、U=Update、D=Delete
                    String operation = erpData.getString("sys_change_operation");

                    String code = erpData.getString("cinvcode"); // 存货编码
                    List<JSONObject> searchList = crmData.stream().filter(object -> Objects.nonNull(object.getString("Product_Code")) &&
                            object.getString("Product_Code").equals(code) && object.getString("AffiliatedCompany").equals(companyName)).collect(Collectors.toList());

                    if (accountCode.equals(DatasourceEnum.GONG_CHANG.getAccountCode())) {  // 因为工厂会转码，所以要重新查询
                        List<JSONObject> filterList = transferList.stream().filter(obj -> obj.getString("Name").equals(code)).collect(Collectors.toList());
                        if (filterList.size() > 0) {
                            JSONObject jsonObject = filterList.get(0);
                            String crm_code = jsonObject.getString("crm_code"); // crm 中对应的编码
                            List<JSONObject> collect = crmData.stream().filter(object -> Objects.nonNull(object.getString("Product_Code")) &&
                                    object.getString("Product_Code").equals(crm_code) && object.getString("AffiliatedCompany").equals(companyName)).collect(Collectors.toList());
                            if (collect.size() > 0) {
                                searchList = collect;
                            }
                        }
                    }

                    if ("I".equals(operation)) {
                        insertList.add(erpData);
                    } else if ("U".equals(operation)) {
                        if (searchList.size() > 0) {
                            JSONObject jsonObject = searchList.get(0);
                            String crmId = jsonObject.getString("id");
                            erpData.put("crmId", crmId);
                            updateList.add(erpData);
                        }
                    } else if ("D".equals(operation)) {
                        log.info("存货档案删除数据：{}", erpData.toJSONString());
                        log.info("存货档案searchList：{}", JSONObject.toJSONString(searchList));
                        if (searchList.size() > 0) {
                            JSONObject jsonObject = searchList.get(0);
                            String crmId = jsonObject.getString("id");
                            deleteList.add(crmId);
                        }
                    }
                }
            }

            // 5 字段映射
            List<JSONObject> crm_insertList = getCrmMappingData(insertList, accountCode, companyName, transferList);
            List<JSONObject> crm_updateList = getCrmMappingData(updateList, accountCode, companyName, transferList);
            System.out.println("crm_insertList.size() = " + crm_insertList.size());
            System.out.println("crm_updateList.size() = " + crm_updateList.size());
            System.out.println("deleteList.size() = " + deleteList.size());

            // 6 批量操作
            CrmApiUtil.batchInsertDataByList(zohoRecord.getAccessToken(), crm_insertList, synModuleName);
            CrmApiUtil.batchUpdateDataByList(zohoRecord.getAccessToken(), crm_updateList, synModuleName);
            if (deleteList.size() > 0) {
                CrmApiUtil.batchDeleteModelData(zohoRecord.getAccessToken(), synModuleName, deleteList);
            }

            // 7 最大版本号回传
            if (queryMaxVersion != maxVersion) {
                CrmApiUtil.saveMaxVersion(zohoRecord.getAccessToken(), versionCrmId, queryMaxVersion, crmPathConfig.getMaxVersionModuleName());
            }

        }


    }

    // 获取CRM映射数据
    private List<JSONObject> getCrmMappingData(List<JSONObject> erpList, String accountCode, String companyName, List<JSONObject> transferList) {
        List<JSONObject> list = new ArrayList<>();

        for (JSONObject erpData : erpList) {
            JSONObject crmData = new JSONObject();
            String crmId = erpData.getString("crmId");
            if (StringUtils.isNotBlank(crmId)) {
                crmData.put("id", crmId);
            }
            crmData.put("AffiliatedCompany", companyName); // 所属公司
            crmData.put("Product_Code", erpData.getString("cinvcode")); // 产品编码
            crmData.put("Product_Name", erpData.getString("cinvname")); // 产品名称
            crmData.put("InventoryCategoryCode", erpData.getString("cinvccode")); // 存货大类编码
            crmData.put("UnitOfMeasurementGroupCode", erpData.getString("cgroupcode")); // 计量单位组编码
            crmData.put("MainUnitOfMeasurementCode", erpData.getString("ccomunitcode")); // 主计量单位编码
            crmData.put("MainUnitOfMeasurement", erpData.getString("ccommainunitname")); // 主计量单位
            crmData.put("InventoryCode", erpData.getString("cinvaddcode")); // 存货代码
            crmData.put("MnemonicCode", erpData.getString("cinvmnemcode")); // 助记码
            crmData.put("igrouptype", erpData.getString("igrouptype")); // 是否多计量
            crmData.put("SpecificationModel", erpData.getString("cinvstd")); // 规格型号
            crmData.put("ProductionMeasurementUnit", erpData.getString("cproductunit")); // 生产计量单位
            crmData.put("CommonName", erpData.getString("ccurrencyname")); // 通用名称
            crmData.put("SalesDefaultUnitOfMeasurementCode", erpData.getString("csacomunitcode")); // 销售默认计量单位编码
            crmData.put("PurchaseDefaultUnitOfMeasurementCode", erpData.getString("cpucomunitcode")); // 采购默认计量单位编码
            crmData.put("InventoryDefaultUnitOfMeasurementCode", erpData.getString("cstcomunitcode")); // 库存默认计量单位编码
            crmData.put("CostDefaultUnitOfMeasurementCode", erpData.getString("ccacomunitcode")); // 成本默认计量单位编码
            crmData.put("RetailMeasurementUnit", erpData.getString("cshopunit")); // 零售计量单位
            crmData.put("CustomsUnitConversionRate", CommonUtil.formatBigDecimal(erpData.getBigDecimal("finvciqexch"), 6)); // 海关单位换算率
            crmData.put("changerate", CommonUtil.formatBigDecimal(erpData.getBigDecimal("ichangrate"), 6)); // 换算率
            crmData.put("ShengChanQiye", erpData.getString("centerprise")); // 生产企业
            crmData.put("PlaceOfOrigin", erpData.getString("caddress")); // 产地
            crmData.put("DomesticSalesOrNot", erpData.getBoolean("bsale")); // 是否内销
            crmData.put("WhetherToExportOrNot", erpData.getBoolean("bexpsale")); // 是否外销
            crmData.put("WhetherToPurchase", erpData.getBoolean("bpurchase")); // 是否采购
            crmData.put("WhetherToProduceAndConsume", erpData.getBoolean("bcomsume")); // 是否生产耗用
            crmData.put("WhetherToOutsource", erpData.getBoolean("bproxyforeign")); // 是否委外
            crmData.put("IsItSelfMade", erpData.getBoolean("bself")); // 是否自制
            crmData.put("IsItUnderProduction", erpData.getBoolean("bproducing")); // 是否在制
            crmData.put("IsTtAPlannedProduct", erpData.getBoolean("bplaninv")); // 是否计划品
            crmData.put("WhetherEntrustedSales", erpData.getBoolean("binventrust")); // 是否受托代销
            crmData.put("ImportedOrNot", erpData.getBoolean("bimport")); // 是否进口
            crmData.put("Sales_Start_Date", CommonUtil.formatTime(erpData.getString("dsdate"))); // 启用日期
            crmData.put("Sales_End_Date", CommonUtil.formatTime(erpData.getString("dedate"))); // 停用日期
            crmData.put("IsShelfLifeManagementInPlace", erpData.getBoolean("binvquality")); // 是否保质期管理
            crmData.put("ShelfLifeUnit", formatShelfLifeUnit(erpData.getString("cmassunit"))); // 保质期单位
            crmData.put("ShelfLifeDays", erpData.getString("imassdate")); // 保质期天数
            crmData.put("IsItBatchManagement", erpData.getBoolean("binvbatch")); // 是否批次管理
            crmData.put("PricingMethod", erpData.getString("cvaluetype")); // 计价方式
            crmData.put("PlannedPriceOrSellingPrice", CommonUtil.formatBigDecimal(erpData.getBigDecimal("iinvrcost"), 2)); // 计划价或售价
            crmData.put("InputTaxRate", CommonUtil.formatBigDecimal(erpData.getBigDecimal("iimptaxrate"), 2)); // 进项税率
            crmData.put("OutputTaxRate", CommonUtil.formatBigDecimal(erpData.getBigDecimal("itaxrate"), 2)); // 销项税率
            crmData.put("ReferenceCost", CommonUtil.formatBigDecimal(erpData.getBigDecimal("iinvsprice"), 5)); // 参考成本
            crmData.put("LatestCost", CommonUtil.formatBigDecimal(erpData.getBigDecimal("iinvncost"), 5)); // 最新成本
            crmData.put("ReferenceCellingPrice", CommonUtil.formatBigDecimal(erpData.getBigDecimal("iinvscost"), 5)); // 参考售价
            crmData.put("MinimumSellingPrice", CommonUtil.formatBigDecimal(erpData.getBigDecimal("iinvlscost"), 5)); // 最低售价
            crmData.put("MaximumPurchasePrice", CommonUtil.formatBigDecimal(erpData.getBigDecimal("iinvmpcost"), 5)); // 最高进价
            crmData.put("wholesalePrice", CommonUtil.formatBigDecimal(erpData.getBigDecimal("fretailprice"), 5)); // 零售价格
            crmData.put("SalesMarkupRate", CommonUtil.formatBigDecimal(erpData.getBigDecimal("iexpsalerate"), 4)); // 销售加成率
            crmData.put("CostRate", CommonUtil.formatBigDecimal(erpData.getBigDecimal("fexpensesexch"), 6)); // 费用率
            crmData.put("IsBarcodeManagementAvailable", erpData.getBoolean("bbarcode")); // 是否条形码管理
            crmData.put("IsItStagnantAndBacklog", erpData.getBoolean("binvoverstock")); // 是否呆滞积压
            crmData.put("SupplyType", formatSupplyType(erpData.getString("isupplytype"))); // 供应类型
            getDifferentFiled(crmData, erpData, accountCode);

            // 工厂产品转码
            if (accountCode.equals(DatasourceEnum.GONG_CHANG.getAccountCode())) {
                String cinvc1name = erpData.getString("cinvc1name"); // 一级分类
                if (cinvc1name.trim().equals("产成品")) {
                    String erpCode = erpData.getString("cinvcode");
                    List<JSONObject> filterList = transferList.stream().filter(obj -> obj.getString("Name").equals(erpCode)).collect(Collectors.toList());
                    if (filterList.size() > 0) {
                        JSONObject transferData = filterList.get(0);

                        crmData.put("Product_Code", transferData.getString("crm_code")); // 产品编码
                        crmData.put("level_1_classification", transferData.getString("level_1_classification_name")); // 一级分类
                        crmData.put("level_2_classification", transferData.getString("level_2_classification_name")); // 二级分类
                        crmData.put("level_3_classification", transferData.getString("level_3_classification_name")); // 三级分类
                        crmData.put("level_4_classification", transferData.getString("level_4_classification_name")); // 四级分类
                        crmData.put("level_5_classification", transferData.getString("level_5_classification_name")); // 五级分类
                        list.add(crmData);
                    }
                }
            } else {
                crmData.put("level_1_classification", erpData.getString("cinvc1name")); // 一级分类
                crmData.put("level_2_classification", erpData.getString("cinvc2name")); // 二级分类
                crmData.put("level_3_classification", erpData.getString("cinvc3name")); // 三级分类
                crmData.put("level_4_classification", erpData.getString("cinvc4name")); // 四级分类
                crmData.put("level_5_classification", erpData.getString("cinvc5name")); // 五级分类
                list.add(crmData);
            }

        }
        return list;
    }

    // 供应类型
    private String formatSupplyType(String type) {
        if (Objects.isNull(type)) return "";
        switch (type) {
            case "0":
                return "领用";
            case "1":
                return "入库倒冲";
            case "2":
                return "工序倒冲";
            case "3":
                return "虚拟件";
            case "4":
                return "直接供应";
        }
        return "";
    }

    // 保质期单位
    private String formatShelfLifeUnit(String unit) {
        if (Objects.isNull(unit)) return "";
        switch (unit) {
            case "1":
                return "年";
            case "2":
                return "月";
            case "3":
                return "日";
        }
        return "";
    }


    // 每个公司，字段取值不一样
    private void getDifferentFiled(JSONObject crmData, JSONObject erpData, String dataSource) {

        JSONObject freeObj = null;
        JSONArray entry = erpData.getJSONArray("entry");
        if (Objects.nonNull(entry)) {
            List<JSONObject> jsonpObjects = entry.toJavaList(JSONObject.class);
            freeObj = jsonpObjects.get(0);
        }
        if (dataSource.equals(DatasourceEnum.SU_ZHOU.getAccountCode())) { // 【苏州】
            crmData.put("PackagingSize", erpData.getString("cinvdefine1")); // 包装尺寸
            crmData.put("EstimatedIdentification", erpData.getString("cinvdefine2")); // 暂估标识
            crmData.put("ProductLineManager", erpData.getString("cinvdefine6")); // 产品线经理
            crmData.put("DangerousGoodsAndGeneralCargo", erpData.getString("cinvdefine4")); // 危货普货
            crmData.put("DangerousGoodsCCategory", erpData.getString("cinvdefine5")); // 危货类别
            crmData.put("ProductSupplier", erpData.getString("cinvdefine7")); // 产品供货商
            crmData.put("Price1", CommonUtil.formatBigDecimal(erpData.getBigDecimal("cinvdefine14"), 6)); // 售价1
            crmData.put("StoragePrecautions", erpData.getString("cinvdefine8")); // 存储注意事项
            crmData.put("TransportationPrecautions", erpData.getString("cinvdefine9")); // 运输注意事项
            crmData.put("PackagingWeight", CommonUtil.formatBigDecimal(erpData.getBigDecimal("cinvdefine13"), 6)); // 包装重量
        } else if (dataSource.equals(DatasourceEnum.CHANG_ZHOU.getAccountCode())) { // 【常州】
            crmData.put("SI", erpData.getString("cinvdefine1")); // SI:
            crmData.put("EstimatedIdentification", erpData.getString("cinvdefine2")); // 暂估标识
            crmData.put("ProductLineManager", erpData.getString("cinvdefine3")); // 产品线经理
            crmData.put("DangerousGoodsAndGeneralCargo", erpData.getString("cinvdefine4")); // 危货普货
            crmData.put("DangerousGoodsCCategory", erpData.getString("cinvdefine5")); // 危货类别
            crmData.put("ShengChanChangShang", erpData.getString("cinvdefine6")); // 生产厂商
            crmData.put("ProductSupplier", erpData.getString("cinvdefine7")); // 产品供货商
            crmData.put("SpecialShelfLife", erpData.getString("cinvdefine8")); // 特殊保质期：
            crmData.put("ProductGrade", erpData.getString("cinvdefine10")); // 产品牌号
            crmData.put("Price1", CommonUtil.formatBigDecimal(erpData.getBigDecimal("cinvdefine14"), 6)); // 售价1
            crmData.put("PlaceOfOrigin", erpData.getString("cinvdefine9")); // 产地
            if (Objects.nonNull(freeObj)) {
                crmData.put("NetWeight", freeObj.getString("free1")); // 净重：
            }
        } else if (dataSource.equals(DatasourceEnum.DA_LIAN.getAccountCode())) { // 【大连总部】
            crmData.put("SI", erpData.getString("cinvdefine1")); // SI:
            crmData.put("EstimatedIdentification", erpData.getString("cinvdefine2")); // 暂估标识
            crmData.put("ProductLineManager", erpData.getString("cinvdefine3")); // 产品线经理
            crmData.put("DangerousGoodsAndGeneralCargo", erpData.getString("cinvdefine4")); // 危货普货
            crmData.put("DangerousGoodsCCategory", erpData.getString("cinvdefine5")); // 危货类别
            crmData.put("ShengChanChangShang", erpData.getString("cinvdefine6")); // 生产厂商
            crmData.put("ProductSupplier", erpData.getString("cinvdefine7")); // 产品供货商
            crmData.put("SpecialShelfLife", erpData.getString("cinvdefine8")); // 特殊保质期：
            crmData.put("TaxClassificationCode", erpData.getString("cinvdefine9")); // 税收分类编码：
            crmData.put("ProductGrade", erpData.getString("cinvdefine10")); // 产品牌号
            crmData.put("Price1", CommonUtil.formatBigDecimal(erpData.getBigDecimal("cinvdefine14"), 6)); // 售价1
            if (Objects.nonNull(freeObj)) {
                crmData.put("NetWeight", freeObj.getString("free1")); // 净重：
            }
        } else if (dataSource.equals(DatasourceEnum.XIN_CAI_LIAO.getAccountCode())) { // 【常州新材料】
            crmData.put("SI", erpData.getString("cinvdefine1")); // SI:
            crmData.put("EstimatedIdentification", erpData.getString("cinvdefine2")); // 暂估标识
            crmData.put("ProductLineManager", erpData.getString("cinvdefine3")); // 产品线经理
            crmData.put("DangerousGoodsAndGeneralCargo", erpData.getString("cinvdefine4")); // 危货普货
            crmData.put("DangerousGoodsCCategory", erpData.getString("cinvdefine5")); // 危货类别
            crmData.put("ShengChanChangShang", erpData.getString("cinvdefine6")); // 生产厂商
            crmData.put("ProductSupplier", erpData.getString("cinvdefine7")); // 产品供货商
            crmData.put("SpecialShelfLife", erpData.getString("cinvdefine8")); // 特殊保质期：
            crmData.put("TaxClassificationCode", erpData.getString("cinvdefine9")); // 税收分类编码：
            crmData.put("ProductGrade", erpData.getString("cinvdefine10")); // 产品牌号
            crmData.put("Price1", CommonUtil.formatBigDecimal(erpData.getBigDecimal("cinvdefine14"), 6)); // 售价1
            if (Objects.nonNull(freeObj)) {
                crmData.put("NetWeight", freeObj.getString("free1")); // 净重：
            }
        } else if (dataSource.equals(DatasourceEnum.GONG_CHANG.getAccountCode())) { // 【工厂】
            crmData.put("DangerousGoodsAndGeneralCargo", erpData.getString("cinvdefine4")); // 危货普货
            crmData.put("DangerousGoodsCCategory", erpData.getString("cinvdefine7")); // 危货类别
            crmData.put("Price1", CommonUtil.formatBigDecimal(erpData.getBigDecimal("cinvdefine14"), 6)); // 售价1
            //crmData.put("InventoryName1", erpData.getString("cinvdefine5")); // 存货名称1
            crmData.put("SpecificationModel1", erpData.getString("cinvdefine6")); // 规格型号1
        }
    }
}
